package com.daervin.svc.common.dto;

import com.daervin.svc.common.exception.ErrorCode;

/**
 * Created by daervin on 2023/8/18
 */
public class ResponseVO<T> {
    private Integer code;
    private String msg;
    private T data;

    public ResponseVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseVO(ErrorCode errorCode, T data) {
        this.code = errorCode.code;
        this.msg = errorCode.message;
        this.data = data;
    }

    public static <T> ResponseVO success(T data) {
        ResponseVO response = new ResponseVO(ErrorCode.SUCCESS, data);
        return response;
    }

    public static ResponseVO error(Integer code, String msg) {
        return new ResponseVO(code, msg, null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
